package com.atguigu07.object.equals;

import java.util.Objects;

public class UserTest {
    public static void main(String[] args) {
        User u1=new User("tom",23);
        User u2=new User("tom",23);
        System.out.println(u1 == u2);
        System.out.println(u1.equals(u2));

        String s1=new String("456");
        String s2=new String("456");
        System.out.println(s1 == s2);
        System.out.println(s1.equals(s2));
    }
}
class User{
    String name;
    int age;

    public User() {
    }

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if(o instanceof User){
            User u=(User)o;
            if(u.age==this.age&&this.name.equals(u.name))//这里比较名字的时候不能用=={
            {
                return true;
            }
        }
        return false;

    }


}